package cn.chair.controller.admin;

import cn.chair.dao.UserWebDao;
import cn.chair.model.admin.UserWebResp;
import life.innovation.exception.DataReadException;
import life.innovation.model.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping(value="user")
@RestController
public class UserWebController {

    @Autowired
    @Lazy
    private UserWebDao userWebDao;

    /**
     * 查询会员（用户）信息
     * @param userId
     * @param mobile
     * @param page
     * @param countPerPage
     * @return
     * @throws DataReadException
     */
    @GetMapping(value = "getUsers")
    public UserWebResp getUser(@RequestParam(required = false) Integer userId,
                               @RequestParam(required = false) String mobile,
                               @RequestParam(required = false,defaultValue = "1")int page,
                               @RequestParam(required = false,defaultValue = "20") int countPerPage) throws DataReadException {

        UserWebResp resp = new UserWebResp();
        PageList<UserWebResp.UserList> list = userWebDao.getUser(userId,mobile,page,countPerPage);

        resp.setPagination(list.getPagination());
        resp.setList(list.getList());

        return resp;
    }

}
